import unittest
import os.path

from kivy.lang import Builder

from ui.presenter_mock import PresenterMock
from ui.edit_players import EditPlayers
from ui.edit_players import PlayerListElement
from model import gamestate


class EditPlayersTest(unittest.TestCase):
    def setUp(self):
        Builder.load_file(os.path.join(os.path.dirname(__file__),
                          'editplayers.kv'))
        players = [gamestate.Player('Player1', []),
                   gamestate.Player('Player2', []),
                   gamestate.Player('Player3', []),
                   gamestate.Player('Player4', [])
                   ]
        players = gamestate.Players(players)
        self.gamestate = gamestate.GameState(players,
                                             None,
                                             None,
                                             None,
                                             None,
                                             None,
                                             None)
        self.presenter = PresenterMock(gamestate.Phase.FROM_TO,
                                       gamestate.Phase.QUICK_GAME_SETTINGS)

    def test_next_screen(self):
        widget = EditPlayers(self.gamestate, self.presenter)
        self.assertEquals(self.presenter.is_phase_changed, False)
        widget.next_screen()
        self.assertEquals(self.presenter.is_phase_changed, True)

    def test_prev_screen(self):
        widget = EditPlayers(self.gamestate, self.presenter)
        self.assertEquals(self.presenter.is_phase_changed, False)
        widget.prev_screen()
        self.assertEquals(self.presenter.is_phase_changed, True)

    def test_change_name(self):
        widget = EditPlayers(self.gamestate, self.presenter)
        self.assertEquals(widget.next_button.enabled, True)
        widget.text_inputs[1].change_name('Player1')
        self.assertEquals(widget.next_button.enabled, False)
        widget.text_inputs[1].change_name('Player3')
        self.assertEquals(widget.next_button.enabled, False)
        widget.text_inputs[1].change_name('Player2')
        self.assertEquals(widget.next_button.enabled, True)

if __name__ == '__main__':
    unittest.main()
